# coding:utf-8

import pymongo
from ztp_backend.settings import DATABASES

HOST = DATABASES["mongodb"]["HOST"]
PORT = DATABASES["mongodb"]["PORT"]
DB = DATABASES["mongodb"]["NAME"]
ACCOUNT = DATABASES["mongodb"].get("USER")
PASSWORD = DATABASES["mongodb"].get("PASSWORD")

py_dbclient = pymongo.MongoClient("mongodb://{}:{}/".format(HOST, PORT))
collections = py_dbclient[DB]
if ACCOUNT and PASSWORD:
    collections = py_dbclient["admin"]
    collections.authenticate(ACCOUNT, PASSWORD)
